﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace EntityFrameWorkCore.Migrations
{
    public partial class init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Permissions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PermissionsCode = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    PermissionsName = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    Description = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SplitArea = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    TimeStamp = table.Column<byte[]>(type: "timestamp", rowVersion: true, nullable: false),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Permissions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Role",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RoleName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    RoleDescribe = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    SplitArea = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    TimeStamp = table.Column<byte[]>(type: "timestamp", rowVersion: true, nullable: false),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Role", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "RolePermissions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RoleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PermissionsId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SplitArea = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    TimeStamp = table.Column<byte[]>(type: "timestamp", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RolePermissions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "User",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    PassWord = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    EmailAddress = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    Phone = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    SplitArea = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    TimeStamp = table.Column<byte[]>(type: "timestamp", rowVersion: true, nullable: false),
                    CreateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeleteUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeleteTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_User", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "UserPermissions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PermissionsId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SplitArea = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    TimeStamp = table.Column<byte[]>(type: "timestamp", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserPermissions", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "UserRole",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RoleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SplitArea = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    TimeStamp = table.Column<byte[]>(type: "timestamp", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserRole", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Permissions_CreateTime_CreateUserId",
                table: "Permissions",
                columns: new[] { "CreateTime", "CreateUserId" });

            migrationBuilder.CreateIndex(
                name: "IX_Permissions_PermissionsCode_PermissionsName_Description",
                table: "Permissions",
                columns: new[] { "PermissionsCode", "PermissionsName", "Description" });

            migrationBuilder.CreateIndex(
                name: "IX_Permissions_SplitArea",
                table: "Permissions",
                column: "SplitArea");

            migrationBuilder.CreateIndex(
                name: "IX_Role_CreateTime_CreateUserId",
                table: "Role",
                columns: new[] { "CreateTime", "CreateUserId" });

            migrationBuilder.CreateIndex(
                name: "IX_Role_RoleName_RoleDescribe",
                table: "Role",
                columns: new[] { "RoleName", "RoleDescribe" });

            migrationBuilder.CreateIndex(
                name: "IX_Role_SplitArea",
                table: "Role",
                column: "SplitArea");

            migrationBuilder.CreateIndex(
                name: "IX_RolePermissions_SplitArea",
                table: "RolePermissions",
                column: "SplitArea");

            migrationBuilder.CreateIndex(
                name: "IX_User_CreateTime_CreateUserId",
                table: "User",
                columns: new[] { "CreateTime", "CreateUserId" });

            migrationBuilder.CreateIndex(
                name: "IX_User_DeleteTime_DeleteUserId_IsDeleted",
                table: "User",
                columns: new[] { "DeleteTime", "DeleteUserId", "IsDeleted" });

            migrationBuilder.CreateIndex(
                name: "IX_User_SplitArea",
                table: "User",
                column: "SplitArea");

            migrationBuilder.CreateIndex(
                name: "IX_User_UpdateUserId_UpdateTime",
                table: "User",
                columns: new[] { "UpdateUserId", "UpdateTime" });

            migrationBuilder.CreateIndex(
                name: "IX_User_UserName_EmailAddress_Phone",
                table: "User",
                columns: new[] { "UserName", "EmailAddress", "Phone" });

            migrationBuilder.CreateIndex(
                name: "IX_UserPermissions_SplitArea",
                table: "UserPermissions",
                column: "SplitArea");

            migrationBuilder.CreateIndex(
                name: "IX_UserRole_SplitArea",
                table: "UserRole",
                column: "SplitArea");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Permissions");

            migrationBuilder.DropTable(
                name: "Role");

            migrationBuilder.DropTable(
                name: "RolePermissions");

            migrationBuilder.DropTable(
                name: "User");

            migrationBuilder.DropTable(
                name: "UserPermissions");

            migrationBuilder.DropTable(
                name: "UserRole");
        }
    }
}
